<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Images Gallery</title>
<style type="text/css">
<!--
.style1 {font-family: Geneva, Arial, Helvetica, sans-serif}
.style6 {
	font-size: 20px;
	font-weight: bold;
	color: #FFFFFF;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: smaller; }
-->
</style>
</head>

<body>
<form action="Bai4_8.php" method="post">
<table width="400" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#BBEEDB">
  <tr>
    <td colspan="2" align="center" bgcolor="#339999"><span class="style6">XEM THƯ MỤC HÌNH ẢNH</span></td>
    </tr>
  <tr>
    <td><span class="style8">Chọn thư mục hình:</span></td>
    <td><span class="style1">
      <select name="ten_tm" id="ten_tm">
      <?php
	  	$dir=opendir("image_gallery");
		if($dir)
		{
			while(($file=readdir($dir))!==false)
			{
				if(!strstr($file,"."))	
				{
					echo "<option value='$file'";
					if($_POST['ten_tm']==$file)
						echo " selected='selected' ";
					echo ">$file</option>";	
				}
			}
			closedir($dir);
		}
	  ?>
      </select>
    </span> </td>
  </tr>
  <tr>
    <td width="170"><span class="style8">Kích cỡ hiển thị: </span></td>
    <td width="216"><span class="style1">
      <label>
        <select name="size" id="size">
          <option value="50" <?php if($_POST['size']==50) echo "selected='selected'";?>>50 x 50</option>
          <option value="100" <?php if($_POST['size']==100) echo "selected='selected'";?>>100 x 100</option>
          <option value="150" <?php if($_POST['size']==150) echo "selected='selected'";?>>150 x 150</option>
          <option value="200" <?php if($_POST['size']==200) echo "selected='selected'";?>>200 x 200</option>
        </select>
        </label>
    </span></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
      <input type="submit" name="Submit" value="Xem hình ảnh">    </td>
    </tr>
</table>
</form>

<p>
<?php
	if(isset($_POST['ten_tm']))
	{
		$size=$_POST['size'];
		$fileTypes=array(".jpg",".jpeg",".gif",".png");
		$ten_tm=$_POST['ten_tm'];
		echo "<table  style='align:center' width=650px><tr>";
		$dir=opendir("image_gallery/".$ten_tm);
		if($dir)
		{
			while(($file=readdir($dir))!==false)
			{
				if($file!="." && $file!="..")
				{
					$extension=strstr($file,".");
					if(in_array($extension,$fileTypes))
					{
						$ten_file="image_gallery/".$ten_tm."/".$file;
						echo "<img src='$ten_file' width='$size' height='$size' border=1 />";	
					}
				}
			}
			closedir($dir);
		}
		echo "</tr></table>";
	}
?>

</body>
</html>
